﻿using System.Collections.Generic;
using System.Linq;
using MSAcademic.v2.Database;

namespace MSAcademic.v2.Infrastructure.Picture.Impl
{
    public class PictureQueriesImpl : IPictureQueries
    {
        public List<IPicture> GetPictures(int galleryId)
        {
            using (var db = new MSAcademicDatabaseContainer())
            {
                var gallery = db.Pictures.Where(m => m.GalleryId == galleryId).Select(g => g);
                return Enumerable.Cast<IPicture>(gallery.Select(picture => new PictureImpl
                                                                                   {
                                                                                       Caption = picture.Caption, GalleryId = picture.GalleryId, Id = picture.Id, IsHidden = picture.IsHidden, Url = picture.Url
                                                                                   })).ToList();
                
            }

        }
        public IPicture GetPicture(int pictureId)
        {
            using (var db = new MSAcademicDatabaseContainer())
            {
                var picture = db.Pictures.SingleOrDefault(m => m.Id == pictureId);
                if(picture!=null)
                {
                    return new PictureImpl(picture);

                }
                return null;
            }
        }
    }


}
